package com.cneiu.ppms.web.service;

import java.util.Map;

import com.cneiu.ppms.web.base.BaseService;
import com.cneiu.ppms.web.model.MenuModel;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
/**
 * 菜单业务
 * @author zhaokf
 * @date 2013-04-23
 */
public class MenuService extends BaseService
{
	/**
	 * 增加菜单信息
	 * @param no
	 * @param name
	 * @param type
	 * @return
	 */
	public static boolean isAdd(Map<String,String> params){
		Record record = new Record();
		record.set("menu_no", Db.queryBigDecimal("select sa_menu_seq.nextval from dual").intValue());
		record.set("menu_name", params.get("menu_name").toString());
		record.set("menu_parent", params.get("menu_parent").toString());
		record.set("menu_icon", params.get("menu_icon").toString());
		record.set("menu_module_a", params.get("menu_module_a").toString());
		record.set("menu_module_c", params.get("menu_module_c").toString());
		boolean isupadded = Db.save("sa_menu", "menu_no",record);
		if(isupadded){
			return true;
		}
		return setError("你访问的菜单已存在！");
	}

	/**
	 * 修改菜单信息
	 * @param no
	 * @param name
	 * @param type
	 * @return
	 */
	public static boolean isUpdate(Map<String,String> params){
		Record record = new Record();
		record.set("menu_no", params.get("menu_no").toString());
		record.set("menu_name", params.get("menu_name").toString());
		record.set("menu_parent", params.get("menu_parent").toString());
		record.set("menu_icon", params.get("menu_icon").toString());
		record.set("menu_module_a", params.get("menu_module_a").toString());
		record.set("menu_module_c", params.get("menu_module_c").toString());
		boolean isupadded = Db.save("sa_menu", "menu_no",record);
		if(isupadded){
			return true;
		}
		return setError("您访问的菜单不存在！");
	}
	
	/**
	 * 根据ID查询菜单
	 * @param params
	 * @return
	 */
	public static MenuModel get(Map<String,String> params){
		String no = params.get("menu_no")==null?"":params.get("menu_no").toString();
		MenuModel mm = MenuModel.dao.findFirst("SELECT * FROM SA_MENU WHERE MENU_NO=?", no);
		return mm;
	}

	/**
	 * 删除菜单信息
	 * @param no
	 * @return
	 */
	public static boolean isDelete(Map<String,String> params){
		String no = params.get("menu_no")==null?"":params.get("menu_no").toString();
		String sql = "select * from sa_menu where menu_no=?";
		MenuModel mm = MenuModel.dao.findFirst(sql, no);
		if (mm != null)
		{
			mm.delete();
			return true;
		}
		return setError("您访问的菜单不存在！");
	}
}
